package com.eqxiu.ieditor.homepage.controller;


import com.eqxiu.ieditor.api.HomePageUserServiceApi;
import com.eqxiu.ieditor.api.IRecommondServiceApi;
import com.eqxiu.ieditor.api.controller.BaseApiController;
import com.eqxiu.ieditor.commons.page.PageDTO;
import com.eqxiu.ieditor.commons.web.ResultData;
import com.eqxiu.ieditor.dto.HomePageUserDTO;
import com.eqxiu.ieditor.dto.RecommondDTO;
import com.eqxiu.ieditor.request.RecommondRequest;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.collect.Maps;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Controller
@Api(description = "推荐内容")
public class RecommmondController implements BaseApiController {
    private final Logger LOGGER = LoggerFactory.getLogger(RecommmondController.class);

    @Autowired
    private IRecommondServiceApi recommondServiceApi;

    /**
     * 获取推荐内容
     * @return
     */
    @PostMapping("api/homepage/getRecommond")
    @ResponseBody
    @ApiOperation(value = "获取推荐内容，全部必填，type 0-用户中心，1-wap商城")
    public ResultData getHomePageUserMessage(int type,int pageNo,int pageSize) {

        try {
            RecommondRequest request = new RecommondRequest();
            request.setPageSize(pageSize);
            request.setPageNo(pageNo);
            request.setRecommondUsePosition(type);
            request.setStatus(1);
            PageDTO<RecommondDTO> pageInfo = recommondServiceApi.queryRecommondPage(request);
            Map<String, Object> map = Maps.newHashMap();
            map.put("total", pageInfo.getCount());
            map.put("rows", pageInfo.getList());
            return success().setMap(map);
        } catch (Exception e) {
            LOGGER.error(e.getMessage());
            return fail().setMsg("get recommond error");
        }
    }

}
